home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / PTR-TCL v2.1 / Support / New TCL Source / x.cp < prev    next >
Encoding:
Text File  |  1994-02-17  |  2.9 KB  |  169 lines  |  [TEXT/MMCC]

  1. /*
  2.  * x.c ©1993 Jon Wätte (h+@nada.kth.se) All Rights Reserved
  3.  *
  4.  * Please read the paragraph marked $$$ in x.h before you use this source
  5.  * file.
  6.  *
  7.  * This file may be used and distributed for free, if certain conditions
  8.  * are met. These conditions are outlined in the accompanying file x.h.
  9.  * This file may NOT be distributed if it is in any way modified from the
  10.  * original as distributed by Jon Wätte. Also it may only be distributed
  11.  * accompanying the file x.h. See x.h for details.
  12.  *
  13.  * v1.0 930826 - Initial release
  14.  * v1.1 940121 - TCL replacement version
  15.  */
  16.  
  17. #include <Dialogs.h>
  18. #include <SegLoad.h>
  19.  
  20. #include "Exceptions.h"
  21.  
  22.  
  23. long
  24. SpecifyMsg ( short suite , short id ) {
  25.     if ( suite < 1024 ) {
  26.         suite += 1024 ;
  27.     }
  28.     return ( ( unsigned long ) suite << 16 ) + id ;
  29. }
  30.  
  31.  
  32. jmp_buf * __cur_buf = NULL ;
  33. #ifdef FAILINFO
  34. char * __err_file = NULL ;
  35. int __err_line = 0 ;
  36. #endif
  37.  
  38. short gLastError ;
  39. long gLastMessage ;
  40. Boolean gBreakFailure ;
  41.  
  42. static void
  43. UncaughtException ( void ) {
  44.  
  45. #if DEBUG
  46. // Check __err_file and __err_line if available!
  47.     DebugStr ( "\pException uncaught!" ) ;
  48. #endif
  49.  
  50. // At least give the user SOME feedback before quitting
  51.  
  52.     ParamText ( "\pUnhandled error!" , NULL , NULL , NULL ) ;
  53.     Alert ( 128 , NULL ) ;
  54.     ExitToShell ( ) ;
  55. }
  56.  
  57.  
  58. #ifdef FAILINFO
  59. void
  60. __FailNil ( void * p , char * file , int line ) {
  61.     if ( ! p ) {
  62.         __err_file = file ;
  63.         __err_line = line ;
  64.         gLastMessage = 0 ;
  65.         gLastError = -108 ;
  66. #if DEBUG
  67.         if ( gBreakFailure ) {
  68.             Debugger ( ) ;
  69.         }
  70. #endif
  71.         if ( __cur_buf ) {
  72.             longjmp ( * __cur_buf , -108 ) ;
  73.         }
  74.         UncaughtException ( ) ;
  75.     }
  76. }
  77.  
  78.  
  79. void
  80. __FailErr ( short err , char * file , int line ) {
  81.     if ( err ) {
  82.         __err_file = file ;
  83.         __err_line = line ;
  84.         gLastMessage = 0 ;
  85.         gLastError = err ;
  86. #if DEBUG
  87.         if ( gBreakFailure ) {
  88.             Debugger ( ) ;
  89.         }
  90. #endif
  91.         if ( __cur_buf ) {
  92.             longjmp ( * __cur_buf , err ) ;
  93.         }
  94.         UncaughtException ( ) ;
  95.     }
  96. }
  97.  
  98.  
  99. void
  100. __Failure ( short err , long message , char * file , int line ) {
  101.     __err_file = file ;
  102.     __err_line = line ;
  103.     gLastMessage = 0 ;
  104.     gLastError = err ;
  105. #if DEBUG
  106.     if ( gBreakFailure ) {
  107.         Debugger ( ) ;
  108.     }
  109. #endif
  110.     if ( __cur_buf ) {
  111.         longjmp ( * __cur_buf , err ) ;
  112.     }
  113.     UncaughtException ( ) ;
  114. }
  115.  
  116. #else
  117. void
  118. FailNil ( void * p ) {
  119.     gLastError = -108 ;
  120.     gLastMessage = 0 ;
  121.     if ( ! p ) {
  122. #if DEBUG
  123.         if ( gBreakFailure ) {
  124.             Debugger ( ) ;
  125.         }
  126. #endif
  127.         if ( __cur_buf ) {
  128.             longjmp ( * __cur_buf , -108 ) ;
  129.         }
  130.     }
  131.     UncaughtException ( ) ;
  132. }
  133.  
  134.  
  135. void
  136. FailErr ( short err ) {
  137.     gLastError = err ;
  138.     gLastMessage = 0 ;
  139.     if ( err ) {
  140. #if DEBUG
  141.         if ( gBreakFailure ) {
  142.             Debugger ( ) ;
  143.         }
  144. #endif
  145.         if ( __cur_buf ) {
  146.             longjmp ( * __cur_buf , err ) ;
  147.         }
  148.         UncaughtException ( ) ;
  149.     }
  150. }
  151.  
  152.  
  153. void
  154. Failure ( short err , long message ) {
  155.     gLastError = err ;
  156.     gLastMessage = message ;
  157. #if DEBUG
  158.     if ( gBreakFailure ) {
  159.         Debugger ( ) ;
  160.     }
  161. #endif
  162.     if ( __cur_buf ) {
  163.         longjmp ( * __cur_buf , err ) ;
  164.     }
  165.     UncaughtException ( ) ;
  166. }
  167.  
  168. #endif
  169.